//
//  PTFuncEnum.swift
//  PointTest28
//
//  Created by yoctech on 2025/7/21.
//

import SwiftUI
import Foundation


// 一级
enum PTFuncRequireOne: Int, CaseIterable {
    case tel = 0
    case sms
    case mobileNet
    case wlan
    case location
    case callRecord
    case localRecord
    case screenCaptureAndRecording
    case takePhotoAndVideo
    case receiveSMS
    case contacts
    case readCallLogs
    case readSMS
    case readMMS
    case netBrowsingHistory
    /// 日程表
    case scheduleReading
    case mediaAudio
    /// 生物识别
    case biometrics
    case uuid
    case apps
    case bluetoothOn
    case NFCOn
    case bluetoothPair
}

extension PTFuncRequireOne: PTFunc {
    
    var id: Int {
        self.rawValue
    }
    
    var label: String {
        switch self {
        case .tel: "4.3.1.1.1（一级）拨打电话的受控机制"
        case .sms: "4.3.1.1.3（一级）发送短信的受控机制"
        case .mobileNet: "4.3.1.1.6.2（一级）开启移动通信网络数据连接的受控机制"
        case .wlan: "4.3.1.1.7.2（一级）开启WLAN网络连接的受控机制"
        case .location: "4.3.1.2.1.1（一级）调用定位功能的受控机制"
        case .callRecord: "4.3.1.2.2（一级）通话录音功能启动的受控机制"
        case .localRecord: "4.3.1.2.3（一级）本地录音功能启动的受控机制"
        case .screenCaptureAndRecording: "4.3.1.2.4（一级）后台截屏/录屏功能启动的受控机制"
        case .takePhotoAndVideo: "4.3.1.2.5（一级）拍照/摄像功能启动的受控机制"
        case .receiveSMS: "4.3.1.2.6（一级）接收短信功能启动的受控机制"
        case .contacts: "4.3.1.2.7.1（一级）电话本数据读操作的受控机制"
        case .readCallLogs: "4.3.1.2.7.2（一级）通话记录读操作的受控机制"
        case .readSMS: "4.3.1.2.7.3（一级）短信数据读操作的受控机制"
        case .readMMS: "4.3.1.2.7.4（一级）彩信数据读操作的受控机制"
        case .netBrowsingHistory: "4.3.1.2.7.5（一级）上网记录读操作的受控机制"
        case .scheduleReading: "4.3.1.2.7.6（一级）日程表数据读操作的受控机制"
        case .mediaAudio: "4.3.1.2.7.7（一级）媒体影音数据读操作的受控机制"
        case .biometrics: "4.3.1.2.7.8（一级）生物特征识别信息读操的受控机制"
        case .uuid: "4.3.1.2.7.9（一级）设备唯一可识别信息读操作的受控机制"
        case .apps: "4.3.1.2.7.10（一级）应用软件列表读操作的受控机制"
        case .bluetoothOn: "4.4.1.1.2（一级）蓝牙接口开启的受控机制"
        case .NFCOn: "4.4.1.1.4（一级）NFC接口开启的受控机制"
        case .bluetoothPair: "4.4.1.2（一级）蓝牙配对连接的受控机制"
        }
    }
    
    var title: String {
        switch self {
        case .tel: "拨打电话"
        case .sms: "发送短信"
        case .mobileNet: "开启移动通信网络数据连接"
        case .wlan: "开启WLAN网络连接"
        case .location: "定位功能"
        case .callRecord: "通话录音功能"
        case .localRecord: "本地录音功能"
        case .screenCaptureAndRecording: "后台截屏/录屏功能"
        case .takePhotoAndVideo: "拍照/摄像功能"
        case .receiveSMS: "接收短信功能"
        case .contacts: "电话本数据读操作"
        case .readCallLogs: "通话记录读操作"
        case .readSMS: "短信数据读操作"
        case .readMMS: "彩信数据读操作"
        case .netBrowsingHistory: "上网记录读操作"
        case .scheduleReading: "日程表数据读操作"
        case .mediaAudio: "媒体影音数据读操作"
        case .biometrics: "生物特征识别读操作"
        case .uuid: "设备唯一可识别信息读操作"
        case .apps: "应用软件列表读操作"
        case .bluetoothOn: "蓝牙接口开启"
        case .NFCOn: "NFC接口开启"
        case .bluetoothPair: "蓝牙配对连接"
        }
    }
    
    var desc: [String]? {
        switch self {
        case .sms:
            [
                "输入对方号码和短信内容",
                "构造url链接（\"sms://电话号码\"）",
                "调用WKExtension单例对象的openSystemURL(_:)方法发送短信"
            ]
        case .location:
            [
                "导入CoreLocation框架",
                "watchOS系统无法设置使用哪一种途径进行定位。watchOS的API将底层细节屏蔽，开发人员和用户并不知道现在设备是采用那种方式定位",
                "可以通过设置定位精度间接达到这一目的",
                "调用CLLocationManager对象的requestWhenInUseAuthorization方法申请定位权限",
                "设置CLLocationManager对象的desiredAccuracy属性为kCLLocationAccuracyKilometer表示利用蜂窝网络粗略定位；属性为kCLLocationAccuracyBest表示精确定位",
                "调用CLLocationManager对象的startUpdatingLocation()方法开始定位",
                "通过CLLocationManager对象的代理的locationManager(manager: , didUpdateLocations:)方法返回定位信息",
                "调用CLLocationManager对象的stopUpdatingLocation()方法停止定位"
            ]
            
        case .contacts:
            [
                "导入Contacts框架",
                "此功能需要通讯录权限",
                "通过CNContactStore()requestAccess(for: .contacts)获取联系人权限",
                "初始化联系人存储对象 CNContactStore",
                "定义要获取的联系人字段，类型为[CNKeyDescriptor]",
                "通过CNContactFetchRequest(keysToFetch:)创建批量获取联系人的请求，限制只获取4 中指定的字段",
                "通过CNContactStore对象的enumerateContacts(request:)执行联系人枚举，传入参数为5中的创建的批量获取联系人请求",
                "获取到联系人"
            ]
            
        case .scheduleReading:
            [
                "此功能需要日程表权限",
                "导入EventKit框架",
                "初始化EKEventStore对象",
                "通过EKEventStore对象的requestAccess(to:completion:)方法，请求日历访问权限，此回调会返回授权结果",
                "如果授权成功，通过EKEventStore对象的predicateForEvents(withStart:end:calendars:)方法，生成一个查询谓词，筛选指定时间范围内的事件",
                "通过EKEventStore对象的events(matching: predicate)执行查询并获取事件",
                "获取事件成功"
            ]
        default: nil
        }
    }
    
    var groupDesc: [FunDetailModel]? {
        switch self {
        case .tel:
            [
                .init(subTitle: "拨打电话", subDescs: [
                    "通过输入电话号码，构造url链接（\"tel://xxxxxxxxxxx\"）",
                    "调用WKExtension单例对象的openSystemURL(_:)方法拨出号码"
                ]),
                .init(subTitle: "呼叫转移", subDescs: [
                    "不支持呼叫转移功能"
                ])
            ]
        case .localRecord:
            [
                .init(subTitle: "本地录音", subDescs: [
                    "此功能需要麦克风权限",
                    "调用AVAudioSession.sharedInstance().setCategory(.record)设置音频会话类别为录音和音频输出",
                    "调用AVAudioSession.sharedInstance().setActive(true)激活音频会话，接管设备音频资源并强制中断其他应用的音频会话",
                    "初始化AVAudioRecorder对象，设置录音参数：使用无损PCM编码格式、采样率44.1kHz、立体声录制、高质量编码",
                    "调用AVAudioRecorder对象prepareToRecord()准备录音",
                    "调用AVAudioRecorder对象的record()方法开始录音",
                    "调用AVAudioRecorder对象的stop()方法停止录音"
                ]),
                .init(subTitle: "播放录音", subDescs: [
                    "初始化AVAudioPlayer对象，传入录音文件路径",
                    "调用AVAudioPlayer对象的play()方法播放录音",
                    "调用AVAudioPlayer对象的stop()方法停止播放"
                ])
            ]
        
        case .bluetoothPair:
            [
                .init(subTitle: "配对外设", subDescs: [
                    "导入CoreBluetooth框架",
                    "此功能需要获取蓝牙权限",
                    "在控制中心打开蓝牙",
                    "初始化CBCentralManager对象，并设置代理",
                    "调用CBCentralManager对象的scanForPeripherals(withServices:options:)方法扫描外设",
                    "输入待连接对象的蓝牙MAC地址",
                    "通过CBCentralManager对象的retrievePeripherals(withIdentifiers: uuids)方法，传入待连接对象的蓝牙MAC地址，检索该外设",
                    "通过CBCentralManager对象的connect方法，连接该外设",
                    "连接成功与否会通过CBCentralManager对象的代理返回",
                ]),
                .init(subTitle: "断开连接", subDescs: [
                    "通过CBCentralManager对象cancelPeripheralConnection(:)方法，断开蓝牙连接"
                ])
            ]
        default: nil
        }
    }
}
